<?php
echo form::open('/admin/seminarWizard/next');

if (count($programTypeList) > 0) {
    echo '<h3>' . text::getEscaped('seminarWizard.programTypeAvailability') . '</h3>';
    echo '<p class="description">' . text::getEscaped('seminarWizard.programTypeAvailability-desc') . '</p>';
    echo '<table class="programTypeBatchTable">';
    echo '<thead>';
    echo '<tr>';
    echo '<th></th>';
    foreach ($this->data->batchList as $batch) {
        echo '<th title="' . format::date($batch['begin_date']) . ' - ' . format::date($batch['end_date']) . '">' . $batch['name'] . '</th>';
    }
    // echo '<th></th>';
    echo '</tr>';
    echo '</thead>';
    echo '<tbody>';
    foreach ($programTypeList as $programType) {
        echo '<tr>';
        $onclick = 'checkOrUncheckAllInRow(this.parentNode.parentNode);';
        if ($programType['code'] == 'karmayoga') {
            $onclick .= 'toggleKarmayogaTypes(this.parentNode.parentNode)';
        }
        echo '<th><label class="textWithAction" onclick="' . $onclick . '" title="' . text::getEscaped('seminarWizard.clickToSelectAllBatchesOrNone') . '">' . $programType['name'] . '</label></th>';
        foreach ($this->data->batchList as $index => $batch) {
            $rowIndices = $programTypeForm['batches_of_program_type'][$programType['code']];
            $checked = FALSE;
            if (is_array($rowIndices)) {
                $checked = array_search($index, $rowIndices) !== FALSE;
            }
            $onchange = '';
            if ($programType['code'] == 'karmayoga') {
                $onchange = 'onchange="toggleKarmayogaTypes(this.parentNode.parentNode)"';
            }
            echo '<td>' . form::checkbox('batches_of_program_type[' . $programType['code'] . '][]', $index, $checked, $onchange) . '</td>';
        }
        // echo '<th>' . html::img('select_all.png', array('onclick' => 'checkAllInRow(this.parentNode.parentNode)')) . '</th>';
        echo '</tr>';
    }
    echo '</tbody>';
    echo '</table>';
}

// One day programs
if ($this->data->seminar['singleDaysAllowed']) {
	echo '<h3>' . text::getEscaped('seminarWizard-singleDayBatchProgramTypes') . '</h3>';
	$fb = new FormBuilder('seminarWizard', $programTypeForm);
	$fb->doNotOpenForm();
	$fb->doNotCloseForm();
	$fb->selectMany('single_days_program_type_codes', $singleDayProgramTypeOptions)
	    ->required();
	$fb->write();
}

// Karmayoga
echo '<h3>' . text::getEscaped('seminarWizard.karmayogaTypes') . '</h3>';

$fb = new FormBuilder('seminarWizard', $programTypeForm);
$fb->doNotOpenForm();
$fb->doNotCloseForm();
$fb->selectMany('karmayoga_type_codes', $karmayogaTypeOptions)
    ->required();
$fb->write();

// Exercise groups
echo '<h3>' . text::getEscaped('seminarWizard.availableExerciseGroups') . '</h3>';
$fb = new FormBuilder('exerciseGroup', $programTypeForm);
$fb->doNotOpenForm();
$fb->doNotCloseForm();
$fb->setAction('/admin/seminarWizard/next');
$fb->selectMany('exerciseGroup_codes', $exerciseGroupOptions);
$fb->write();

echo form::close();
?>